package com.hgg.utils;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonUtils {
	public static List<Map<String, Object>> parserJson(String fileName,String mapKey,String listKey) throws JsonParseException, JsonMappingException, IOException {
		ObjectMapper mapper = new ObjectMapper();
		Map readValue = mapper.readValue(new File(fileName),Map.class);
		Map<String,Object> maps = (Map<String, Object>) readValue.get(mapKey);
		List<Map<String, Object>> list = (List<Map<String, Object>>) maps.get(listKey);
		return list;
	}
	public static List<Map<String, Object>> parserJson(InputStream inputStream,String mapKey,String listKey) throws JsonParseException, JsonMappingException, IOException {
		ObjectMapper mapper = new ObjectMapper();
		Map readValue = mapper.readValue(inputStream,Map.class);
		Map<String,Object> maps = (Map<String, Object>) readValue.get(mapKey);
		List<Map<String, Object>> list = (List<Map<String, Object>>) maps.get(listKey);
		return list;
	}



}
